home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / c-tools / c_examples / edit / edit.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-11  |  3.5 KB  |  147 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // edit.cpp
  3. //
  4. // Jeffry A Worth
  5. // November 10, 1995
  6. //////////////////////////////////////////////////////////////////////////////
  7.  
  8. //////////////////////////////////////////////////////////////////////////////
  9. // INCLUDES
  10. #include "aframe:include/edit.hpp"
  11.  
  12. //////////////////////////////////////////////////////////////////////////////
  13. //
  14.  
  15. AFEdit::AFEdit()
  16. {
  17.   m_text=NULL;
  18. }
  19.  
  20. AFEdit::~AFEdit()
  21. {
  22.   DestroyObject();
  23. }
  24.  
  25. void AFEdit::DestroyObject()
  26. {
  27.  
  28.   AFGadget::DestroyObject();
  29.   
  30.   if(m_text) {
  31.     delete m_text;
  32.     m_text=NULL;
  33.   }
  34.   if(m_pbuffer) {
  35.     delete m_pbuffer;
  36.     m_pbuffer=NULL;
  37.   }
  38.   if(m_pundobuffer) {
  39.     delete m_pundobuffer;
  40.     m_pundobuffer=NULL;
  41.   }
  42. }
  43.  
  44. void AFEdit::Create(char *text, AFWindow* pwindow, AFRect *rect, ULONG id, int maxlen)
  45. {
  46.   AFRect grect;
  47.   WORD w,h;
  48.  
  49.   // Setup the rect for the actual strgadget
  50.   grect.SetRect(rect->TopLeft()->m_x+2,rect->TopLeft()->m_y+2,
  51.                 rect->BottomRight()->m_x-2,rect->BottomRight()->m_y-2);
  52.  
  53.   m_maxlen = maxlen;
  54.  
  55.   // Create buffers for the edit control
  56.   m_pbuffer = new char[m_maxlen+1];
  57.   m_pundobuffer = new char[m_maxlen+1];
  58.   m_pbuffer[0]=m_pundobuffer[0]=NULL;
  59.   
  60.   AFGadget::Create(pwindow,&grect,id);
  61.  
  62.   // Create string for the text
  63.   m_text = new char[strlen(text)+1];
  64.   strcpy(m_text,text);
  65.  
  66.   // Fill in coordinates to draw border
  67.   w=rect->Width()-1;
  68.   h=rect->Height()-1;
  69.   m_xyshine[0]=m_xyshine[2]=m_xyshine[3]=m_xyshine[5]=0;
  70.   m_xyshine[1]=h;
  71.   m_xyshine[4]=w;
  72.  
  73.   m_xyshadow[0]=1;
  74.   m_xyshadow[1]=m_xyshadow[3]=h;
  75.   m_xyshadow[2]=m_xyshadow[4]=w;
  76.   m_xyshadow[5]=0;
  77.  
  78.   // Fill in Border Structure
  79.   m_gborder.LeftEdge = m_gborder2.LeftEdge = 0;
  80.   m_gborder.TopEdge = m_gborder2.TopEdge = 0;
  81.   m_gborder.FrontPen = 2;
  82.   m_gborder2.FrontPen = 1;
  83.   m_gborder.BackPen = m_gborder2.BackPen = 0;
  84.   m_gborder.DrawMode = m_gborder2.DrawMode = JAM1;
  85.   m_gborder.Count = m_gborder2.Count = 3;
  86.   m_gborder.XY = m_xyshine;
  87.   m_gborder2.XY = m_xyshadow; 
  88.   m_gborder.NextBorder = &m_gborder2;
  89.   m_gborder2.NextBorder = NULL;
  90.  
  91.   m_sborder.LeftEdge = m_sborder2.LeftEdge = -2;
  92.   m_sborder.TopEdge = m_sborder2.TopEdge = -2;
  93.   m_sborder.FrontPen = 1;
  94.   m_sborder2.FrontPen = 2;
  95.   m_sborder.BackPen = m_sborder2.BackPen = 0;
  96.   m_sborder.DrawMode = m_sborder2.DrawMode = JAM1;
  97.   m_sborder.Count = m_sborder2.Count = 3;
  98.   m_sborder.XY = m_xyshine;
  99.   m_sborder2.XY = m_xyshadow; 
  100.   m_sborder.NextBorder = &m_sborder2;
  101.   m_sborder2.NextBorder = NULL;
  102.  
  103.   // Fill IntuiText Structure
  104.   m_IntuiText.FrontPen = 1;
  105.   m_IntuiText.DrawMode = JAM1;
  106.   m_IntuiText.LeftEdge = 5;
  107.   m_IntuiText.TopEdge = 5;
  108.   m_IntuiText.ITextFont = NULL;
  109.   m_IntuiText.IText = (UBYTE*)m_text;
  110.   m_IntuiText.NextText = NULL;
  111.  
  112.   // Attach IntuiText Struct and Border Struct to gadget Struct
  113.   //m_pgadget->GadgetText = &m_IntuiText;
  114.   m_pgadget->GadgetRender = &m_sborder;
  115.   m_pgadget->SelectRender = &m_gborder;
  116. }
  117.  
  118. void AFEdit::FillGadgetStruct(LPExtGadget psgadget)
  119. {
  120.   AFGadget::FillGadgetStruct(psgadget);
  121.  
  122.   psgadget->GadgetType = GTYP_STRGADGET;
  123.   psgadget->Activation = GACT_RELVERIFY;
  124.   psgadget->Flags = GFLG_TABCYCLE;
  125.   psgadget->SpecialInfo=&m_si;
  126.  
  127.   m_si.Buffer=(UBYTE*)m_pbuffer;
  128.   m_si.UndoBuffer=(UBYTE*)m_pundobuffer;
  129.   m_si.MaxChars=25;
  130.   m_si.BufferPos=0;
  131.   m_si.DispPos=0;
  132. }
  133.  
  134. void AFEdit::SetText(int i)
  135. {
  136.   char text[25];
  137.  
  138.   sprintf(text,"%d",i);
  139.   SetText(text);
  140. }
  141.  
  142. void AFEdit::SetText(char *text)
  143. {
  144.   strncpy(m_pbuffer,text,m_maxlen);
  145.   RefreshGList((LPGadget)m_pgadget,m_pwindow->m_pWindow,NULL,1);
  146. }
  147.